package vip.xiaonuo.smzq.modular.user.controller;

import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vip.xiaonuo.smzq.modular.user.entity.User;
import vip.xiaonuo.smzq.modular.user.entity.vo.UserVo;
import vip.xiaonuo.smzq.modular.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 用户
 *
 * @author sqq
 * @since 2024-04-22
 */
@Api(tags = "用户")
@RestController
@RequestMapping("/user/user")
@Validated
public class UserController {

    @Resource
    private IUserService iUserService;

    /**
     * 添加用户
     */
    @ApiOperation("添加用户")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid User user) {
        iUserService.save(user);
        return CommonResult.ok();
    }

    /**
     * 删除用户
     */
    @ApiOperation("删除用户")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        iUserService.removeById(pkid);
        return CommonResult.ok();
    }

    /**
     * 编辑用户
     */
    @ApiOperation("编辑用户")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid User user) {
        iUserService.updateById(user);
        return CommonResult.ok();
    }

    /**
     * 省级审批矿业权人分页查询
     */
    @ApiOperation("省级审批矿业权人分页查询")
    @GetMapping("/approvalList")
    public CommonResult<Page<UserVo>> page(@ApiParam(name = "current", value = "页数", example = "1", required = true)  @RequestParam long current,
                                           @ApiParam(name = "size", value = "每页数量", example = "20", required = true) @RequestParam long size,
                                           String account,
                                           String name

                                           ) {
        return CommonResult.data(iUserService.page(current, size, account, name));
    }
}
